<?php
require_once ($INCLUDE_PATH . "./include/WebService2Db.php");
class UserModel {
    public function saveUserInfo($s) {
        $s1 = 'id';
        $s2 = "'".$s['id']."'";
        foreach ($s as $key => $ss) {
            if($key != 'id') {
                $s1 .= ",".$key;
                $s2 .= ",'".$ss."'";
            }
        }
        $DB=new DB_MYSQL;
        $sql="insert into `".PRE."_user`(".$s1.")" ."VALUES(".$s2.")";

        //  $sql="SELECT *  FROM `hh_user` WHERE `account` = '".$username."' AND `password` = '".$password."'";
        $query = $DB->insert($sql,DB);
        //  echo $DB->insert_id;
        return $DB->insert_id;
    }
     public function editUserInfo($id,$s) {

        foreach ($s as $key => $ss) {
           
            if($key != "user_type") {
                
                $s1 .= ",".$key."='".$ss."'";
              
            }else{
                 $s1 .= $key."='".$ss."'";
            }
        }
        $DB=new DB_MYSQL;
        $sql="update  `".PRE."_user` set ".$s1.
			" where id=".$id;
      //  $sql="insert into `".PRE."_user`(".$s1.")" ."VALUES(".$s2.")";

        //  $sql="SELECT *  FROM `hh_user` WHERE `account` = '".$username."' AND `password` = '".$password."'";
        $query = $DB->update($sql,DB);
 
        return $DB->affected_rows;
    }
    public function getListCount($where="") {

        $DB=new DB_MYSQL;
        $table=PRE."_user";
        $sum=$DB->count_records($table,"id",$where,DB);
        return $sum;

    // echo $sum;
    }
    public function getList($page,$liststart,$pageSize,$where="") {
        $DB=new DB_MYSQL;
        $sql="SELECT *  FROM `".PRE."_user` ".$where." LIMIT ".$liststart.",".$pageSize;
        $query = $DB->fetch_array($sql,DB);
        return $query;

    }
    public function delUser($id) {
        $DB=new DB_MYSQL;
        $sql = " delete from ".PRE."_user where id=".$id;
        $query = $DB->delete($sql, PRE);
    }
 
}
?>
